import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.log4j.Logger;

public class Test1 {
	private static Logger logger = Logger.getLogger(Test1.class.getName());

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Connection conn = null;
		Statement st = null;
		ResultSet rs = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			logger.error(e);
		}
		try {
			conn = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/student", "zzh", "0000");
			System.out.println("实现类的名字是：" + conn.getClass().getName());
			st = conn.createStatement();// 创建支持语句的对象
			rs = st.executeQuery("select * from subject");
			while (rs.next()) {
				System.out.print(rs.getInt(1)+ "\t");
				System.out.print(rs.getString(2)+ "\t");
				System.out.print(rs.getInt(3)+ "\t");
				System.out.println(rs.getInt(4));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			logger.error(e);
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					logger.error(e);
				}
			}
			if (st != null) {
				try {
					st.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					logger.error(e);
				}
			}
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					logger.error(e);
				}
			}
		}

	}

}
